import logging
import time

import yaml

from page_object.base_page import BasePage
from resource.client_path_info import *
from resource.path_info import *
from util.devices import *


class GuangPage(BasePage):
    """
    封装一些和业务无关的重复代码
    是某些操作的底层
    """


    def intoGuang(self, d):
        print("intoGuangBusiness")
        condition = d.app_current()
        # if condition["package"] != 'com.youzan.guang.business':
        d.app_stop("com.youzan.guang.business")
        d.uiautomator.stop()
        d.uiautomator.start()
        d.app_start("com.youzan.guang.business")
        self.skipAd(d)
        self.checkIntoGuang(d)


    def checkIntoGuang(self, d):
        if d.xpath(userName_xpath).exists:
            print("%s 已进入商家版APP" %(d.xpath(userName_xpath).get_text()))
        else:
            time.sleep(3)
            if not d.xpath(userName_xpath).exists:
                print("进入商家版APP失败")
                raise Exception("进入商家版APP失败")

    def skipAd(self, d):
        d.xpath(main_ad_xpath).wait(timeout=2.0)
        if d.xpath(main_ad_xpath).exists:
            d.xpath(main_ad_xpath).click()




